<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use yii\widgets\Pjax;
use yii\bootstrap\Modal;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\TicketSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Tickets';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="ticket-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <!--<? //= Html::a('Create Ticket', ['create'], ['class' => 'btn btn-success']) ?>-->

        <?= Html::a('Create Ticket', '#', [
            'id'          => 'create',
            'data-toggle' => 'modal',
            'data-target' => '#create-modal',
            'class'       => 'btn btn-success',
        ]); ?>
    </p>

    <?php Pjax::begin(); ?>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel'  => $searchModel,
        'columns'      => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'title',
            //            'ticketLink:raw',
            [
                'attribute' => 'code',
                'value'     => function ($model) {
                    return Html::a($model->code,
                        "https://intranet.tkeasia.com/general/tiki-g-admin_instance_user.php?iid={$model->code}",
                        ['target' => '_blank']);
                },
                'format'    => 'raw',
            ],
            [
                'attribute' => 'rs',
                'value'     => function ($model) {
                    return Html::a($model->rs,
                        "https://rs.tkeasia.com/T{$model->rs}",
                        ['target' => '_blank']);
                },
                'format'    => 'raw',
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

    <?php Pjax::end(); ?>

    <?php
    Modal::begin([
        'id'     => 'create-modal',
        'header' => '<h4 class="modal-title">创建</h4>',
        'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',
    ]);
    Modal::end();
    $requestUrl = Url::toRoute('create');
    $js = <<<JS
$(document).on('click', '#create', function () {
    $.get('{$requestUrl}', {},
        function (data) {
            $('.modal-body').html(data);
        }  
    );
});
JS;
    $this->registerJs($js);
    ?>

</div>
